package com.ganlebao.study.springcloudribbon.basic.ribbonconfig;

import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpRequestInterceptor;
import org.apache.http.client.methods.HttpRequestWrapper;
import org.apache.http.impl.client.HttpClientBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 覆盖 HttpClientConfiguration 的配置
 */
@Configuration
@Slf4j
public class HttpClientFactoryConfig {

    @Bean
    public HttpClientBuilder apacheHttpClientBuilder() {
        return HttpClientBuilder.create().addInterceptorFirst((HttpRequestInterceptor) (request, context) -> {
            if (request instanceof HttpRequestWrapper) {
                log.info("httpClient访问的uri:{}", ((HttpRequestWrapper) (request)).getTarget().toHostString() + "/" + ((HttpRequestWrapper) request).getURI());
            }
        });
    }
}
